package com.os.utils;

import org.yaml.snakeyaml.Yaml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;

/**
 * 读取yaml工具
 */
public class ConfigUtils {

    /**
     * 内存块大小，页面大小也是这个
     */
    public static final String FRAME_SIZE = "frameSize";

    /**
     * 物理内存
     */
    public static final String PHYSICAL_MEMORY = "physicalMemory";


    /**
     * 一个段最多多少页
     */
    public static final String PAGE_MAX_NUMBER = "pageMaxNumber";

    /**
     * 行长度
     */
    public static final String LINE_LENGTH = "lineLength";


    /**
     * 资源都在Map
     */
    private static Map<String, Object> CONFIG_MAP;




    /**
     * 获取key对应的value
     *
     * @param key
     * @return
     */
    public static Object get(String key) {
        return CONFIG_MAP.get(key);
    }


    // 读取yaml文件，放在CONFIG_MAP之中
    public static void refresh() {
        Yaml yaml = new Yaml();
        try {
            FileInputStream inputStream = new FileInputStream(FileUtils.getPathOfRes("config.yaml"));
            CONFIG_MAP = yaml.load(inputStream);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }

    }


}
